/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import DAL.MyConnect;
import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.Timer;

/**
 *
 * @author nvc11190
 */
public class ProcessBarSetting {
    final static int interval = 30;
    int i=0;
    JLabel label;
    JProgressBar pb;
    Timer timer;
    JButton button;
    JFrameConfig Config;
    
    public ProcessBarSetting(final JFrameConfig Config){
        this.Config = Config;
        final JFrame frame = new JFrame("Đang Kết Hệ Thống...");
        pb = new JProgressBar(0,100);
        pb.setValue(0);
        pb.setStringPainted(true);
        JPanel panel = new JPanel();
        panel.add(pb);
        frame.setLocationRelativeTo(frame);
        JPanel panel1 = new JPanel();
        panel1.setLayout(new BorderLayout());
        panel1.add(panel,BorderLayout.NORTH);
        panel1.setBorder(BorderFactory.createEmptyBorder(20, 40, 20, 40));
        frame.setContentPane(panel1);
        frame.pack();
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        timer = new Timer(interval,new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (i==100){
                    Toolkit.getDefaultToolkit().beep();
                    timer.stop();
                    frame.dispose();
                    MyConnect conn = new MyConnect();
                    if (conn.testConnection()) {
                        JOptionPane.showMessageDialog(null, "Kết Nối Thành Công!");
                        Config.dispose();
                    }
                    else{ 
                        JOptionPane.showMessageDialog(null, "Kết Nối Thất Bại!");
                        Config.dispose();
                        JFrameConfig Cf = new JFrameConfig();
                        Cf.setVisible(true);
                    }
                    return;
                }
                i =i +1;
                pb.setValue(i);
            }
        });
    
    
}
}
